﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using F_MODEL;
using F_BLL;
using System.Web.SessionState;
using System.Web;
namespace MvcApplication1.Controllers
{

    public class zyl_LoginController : ApiController
    {

        //GET api/values


        UserInfoBll bll = new UserInfoBll();

        /// <summary>
        /// 用户登录  用手机号和密码验证
        /// </summary>
        /// <param name="usertel">手机号码</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        [HttpGet]
        public int zyl_Login(string usertel, string password)
        {

            UserInfo mod = bll.zyl_Login_dal(usertel, password);
            if (mod != null && mod.userId != 0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// 是否登陆
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public UserInfo islogin()
        {

            UserInfo m = mod();
            return m;
        }

        /// <summary>
        /// 其他页面调用的session
        /// </summary>
        /// <returns></returns>
        public UserInfo mod()
        {
            //HttpContext.Current.Request.Headers.Add("Access-Control-Allow-Credentials", "true");
            var cookies = HttpContext.Current.Request.Cookies;
            string userName = HttpContext.Current.Request["userName"];
            string pwd = HttpContext.Current.Request["password"];
            UserInfo m;
            try
            {
                m = bll.zyl_Login_dal(userName, pwd);
            }
            catch (Exception e)
            {

                throw;
            }
            return m;
        }

      


        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="name">用户名</param>
        /// <param name="image">头像</param>
        /// <param name="usertel">联系方式</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        [HttpGet]
        public int zyl_Regist(string usertel, string password)
        {
            return bll.zyl_Regist_dal(usertel, password);
        }
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="usertel">联系方式</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        [HttpGet]
        public int zyl_UpdatePwd(string usertel, string password, string validate)
        {
            return bll.zyl_UpdatePwd_dal(usertel, password);
        }

        /// <summary>
        /// 退出登陆
        /// </summary>
        [HttpGet]
        public void goback()
        {
            //HttpContext.Current.Request.Headers.Add("Access-Control-Allow-Credentials", "true");

            //HttpContext.Current.Session["loginsession"] = null;
        }

    }
}
